import pygame
from pygame.locals import Rect
from text import text
class Bar:
    #static properties
    sysfont = None
    
    def __init__(self, time, pos=(0, 0)):
        if(not Bar.sysfont):
            Bar.sysfont = pygame.font.SysFont('gulim', 36)
        
        self.time = [time, time]
        self.rect = Rect((0, 0, 512, 32))
        self.gaugeRect = Rect((0, 0, 512, 32))

        self.message = Bar.sysfont.render("  ", True, (255, 255, 0))
        self.messageRect = self.message.get_rect()
        self.messageRect.center = self.rect.center
        
        self.rect.move_ip(pos)
        self.gaugeRect.move_ip(pos)
        self.messageRect.move_ip(pos)
    def reset(self, time):
        self.time = [time, time]
        
    def render(self):
        from main import SURFACE
        #gauge
        pygame.draw.rect(SURFACE, 0x009BB2, self.gaugeRect)
        #outline
        pygame.draw.rect(SURFACE, (175, 175, 175), self.rect, 3)
        #time text
        SURFACE.blit(self.message, self.messageRect)
    def update(self, dt):
        if self.time[0] > 0:
            self.time[0] -= dt
        else:
            self.time[0] = 0
        self.gaugeRect.width = 512 * (self.time[0]/self.time[1])

        self.message = Bar.sysfont.render(str('{0:4.1f} '.format(self.time[0]))+ text.getText('second') , True, (255, 255, 0))
        self.messageRect = self.message.get_rect()
        self.messageRect.center = self.rect.center
